<template>
  <div class="me-page">
    <headBar  isBack="show">
      <div slot="xm-header-center">
        <div class="xm-header-title" >资料</div>
      </div>
      <div slot="xm-header-right"></div>
    </headBar>
    <div class="opt-group">
      <div class="item flex flex-pack-justify border-bottom">
        <label v-if="isParent">联系人：</label>
        <label v-if="!isParent">分店联系人：</label>
        <input type="text" class="flex-1 text-right" v-model="userInfo.contacts">
      </div>
      <div class="item flex flex-pack-justify border-bottom">
        <label v-if="isParent" >联系电话：</label>
        <label v-if="!isParent" >分店联系电话：</label>
        <input type="text" class="flex-1 text-right" v-model="userInfo.phone">
      </div>
    </div>
    <div class="opt-group bg-1">
      <div class="item flex flex-pack-justify border-bottom">
        <span>企业名称：</span><span>{{userInfo.buyerName}}</span>
      </div>
      <div class="item flex flex-pack-justify border-bottom">
        <span>企业地址：</span><span>{{userInfo.address}}</span>
      </div>
      <div class="item flex flex-pack-justify border-bottom">
        <span>企业法人：</span><span>{{userInfo.legalPerson}}</span>
      </div>
      <div class="item flex flex-pack-justify border-bottom" v-if="!isParent">
      <span>联系人：</span><span>{{userInfo.parentContacts}}</span>
      </div>
      <div class="item flex flex-pack-justify border-bottom" v-if="!isParent">
      <span>联系电话：</span><span>{{userInfo.parentPhone}}</span>
      </div>
    </div>
    <div class="opt-group save">
      <div class="item login-out border-bottom  btn1" @click="save">保存</div>
    </div>
  </div>
</template>
<script>
  export default {
    props: {},
    data() {
      return {
        userInfo: {
          buyerId: '',
          buyerName: '',
          contacts: '',
          address: '',
          id: '',
          phone: '',
          legalPerson: ''
        },
        isParent: true// 是否为主账号
      };
    },
    methods: {
      getUser(){
        getUser().then(data=>{
          if(data.returnCode == '000000'){
            this.userInfo = data.result;
          }
        })
      },
      save(){
        modifyUser({contacts: this.userInfo.contacts, phone: this.userInfo.phone}).then(data=>{
          if(data.returnCode == '000000'){
            Toast({
              message: '保存成功'
            });
          }else{
            Toast({
              message: data.errorMsg
            });
          }
        })
      }
    },
    filters: {},
    created() {
      this.getUser();
      let parentId = Cookie.get('parentId');
      if(parentId != 'null' && parentId != null){
        this.isParent = false;
      };
    },
    mounted(){

    },
    components: {
    }
  };
</script>
<style lang="less">
  @import "./me.less";
</style>
